﻿using LeRenard.ScriptWars.Model.GridSystem;
using LeRenard.ScriptWars.Model.Scripting;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace LeRenard.ScriptWars.Ui.Otter2DClient
{
    public class Global
    {
        static Global()
        {
            var primaryScreenSize = Screen.PrimaryScreen.Bounds;

            //Window = new Otter.Game("Script Wars");
            Window = new Otter.Game("Script Wars", primaryScreenSize.Width-200, primaryScreenSize.Height-200, 60, fullscreen: false);
            Window.SmoothAll = true;
            Window.MouseVisible = true;            
        }

        /// <summary> 
        /// Holds the game window.
        /// </summary>
        public static Otter.Game Window { get; set; }

        /// <summary>
        /// Holds the current game.
        /// </summary>
        public static ScriptWars.Model.Game Game {
            get {
                if (_game == null)
                    _game = NewGame();

                return _game;
            }
            set {
                _game = value;
            }
        }
        private static ScriptWars.Model.Game _game;

        /// <summary>
        /// Creates a new game.
        /// </summary>
        public static ScriptWars.Model.Game NewGame() {
            var scripts = new List<IScript>();

            var wandererScriptFile = new FileInfo("Content/Scripts/Wanderer.txt");
            var wandererScript = Script.FromFile(wandererScriptFile);
            scripts.Add(wandererScript);
            var linearWalkerScriptFile = new FileInfo("Content/Scripts/LinearWalker.txt");
            var linearWalkerScript = Script.FromFile(linearWalkerScriptFile);
            scripts.Add(linearWalkerScript);
            var squarerScriptFile = new FileInfo("Content/Scripts/Squarer.txt");
            var squarerScript = Script.FromFile(squarerScriptFile);
            scripts.Add(squarerScript);

            return new Model.Game(scripts, new GridSize(15, 15));
        }
    }
}
